mod front_of_house;

// 通过 glob 运算符将所有的公有定义引入作用域
// 如果希望将一个路径下 所有 公有项引入作用域，可以指定路径后跟 *，glob 运算符：
use std::collections::*;

// use crate::front_of_house::hosting;
// 使用 use 和相对路径将模块引入作用域
pub use crate::front_of_house::hosting;

// 定义函数   pub
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

pub fn eat_at_restaurant() {
    hosting::add_to_waitlist();
    hosting::add_to_waitlist();
    hosting::add_to_waitlist();

    // 在夏天订购一个黑麦土司作为早餐
    let mut meal = back_of_house::Breakfast::summer("Rye");
    println!("I get {} toast please", meal.toast);
    // 改变主意更换想要面包的类型
    meal.toast = String::from("Wheat");
    println!("I'd like {} toast please", meal.toast);

    let mut map = HashMap::new();
    map.insert(1, 2);
    println!("map {:#?}.", map);

    // 编译不通过
    // let a = function1();
    // let b = function2();
}

mod back_of_house {
    pub struct Breakfast {
        pub toast: String,
        seasonal_fruit: String,
    }

    impl Breakfast {
        pub fn summer(toast: &str) -> Breakfast {
            Breakfast {
                toast: String::from(toast),
                seasonal_fruit: String::from("peaches"),
            }
        }
    }
}

#[cfg(test)]
mod testsMore {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);


        println!("#################################");
        println!("##     lib test more it_works      ");
        println!("#################################");

        eat_at_restaurant();
    }
}
